/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.football.lottery.ui;

import com.football.lottery.obj.GameItem;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Vector;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author JingWen.Wen
 */
public class GameTableModel extends DefaultTableModel
{
  
  public void addRowWithGameItem(GameItem gameItem)
  {
    Object[] rowDate = new Object[]
    {
      gameItem.getOrderNo(), gameItem.getGameType(), gameItem.getGameTime(), gameItem.getHostName(), gameItem.getScoreline(),
      gameItem.getGuestName(), gameItem.getCompensationRate(), gameItem.getBet(), gameItem.getPreventiveBet()
    };
    this.addRow(rowDate);
  }

  public GameTableModel(Object[][] data, Object[] columnNames)
  {
    super(data, columnNames);
  }
  
  public void addItemRows(List games)
  {
    Iterator it = games.iterator();
    while (it.hasNext())
    {
      GameItem gameItem = (GameItem) it.next();
     this.addRowWithGameItem(gameItem);
    }
  }
  
  public List getItemRows()
  {
    List gameItems = new ArrayList();
    Vector dataRows = this.getDataVector();
    for (Object obj : dataRows)
    {
      Vector rowData = (Vector) obj;
      GameItem item = new GameItem();
      item.setOrderNo((Integer) rowData.get(0));
      item.setGameType((String) rowData.get(1));
      item.setGameTime((Date) rowData.get(2));
      item.setHostName((String) rowData.get(3));
      item.setScoreline((String) rowData.get(4));
      item.setGuestName((String) rowData.get(5));
      item.setCompensationRate((String) rowData.get(6));
      item.setBet((String) rowData.get(7));
      item.setPreventiveBet((String) rowData.get(8));
      gameItems.add(item);
    }
    return gameItems;
  }

  @Override
  public boolean isCellEditable(int row, int column)
  {
    return (column ==7 || column == 8) ? true : false;
  }
  
  public void removeAllRows()
  {
    int rows = this.getRowCount();
    for (int i = rows - 1; i >= 0; i--)
    {
      this.removeRow(i);
    }
  }
  
}
